package com.ruoyi.edge.rule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.rule.domain.RuleInfo;
import com.ruoyi.edge.rule.mapper.RuleInfoMapper;
import com.ruoyi.edge.rule.service.RuleInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 计算规则基本信息
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class RuleInfoServiceImpl implements RuleInfoService {

    private final RuleInfoMapper ruleInfoMapper;

    @Override
    public TableDataInfo<RuleInfo> listPage(RuleInfo ruleInfo, PageQuery pageQuery) {

        LambdaQueryWrapper<RuleInfo> lqw = new LambdaQueryWrapper<>();
        Page<RuleInfo> page = ruleInfoMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public R<RuleInfo> get(String id) {
        RuleInfo ruleInfo = ruleInfoMapper.selectById(id);
        return R.ok(ruleInfo);
    }

    @Override
    public R<String> add(RuleInfo ruleInfo) {
        ruleInfoMapper.insert(ruleInfo);
        return R.ok("新增成功");
    }

    @Override
    public R<String> edit(RuleInfo ruleInfo) {
        ruleInfoMapper.updateById(ruleInfo);
        return R.ok("修改成功");
    }

    @Override
    public R<String> remove(String id) {
        ruleInfoMapper.deleteById(id);
        return R.ok("删除成功");
    }
}
